# -*- coding: utf-8 -*-
"""
@author: YuHaiyang

"""
import os
import shutil
from pathlib import Path, PosixPath


class DataSetUtils:
    @staticmethod
    def test(src_path, dest_path, count: int = 10):
        if isinstance(src_path, str):
            src_path = Path(src_path)
        elif isinstance(src_path, PosixPath):
            src_path = src_path

        if isinstance(dest_path, str):
            dest_path = Path(dest_path)
        elif isinstance(dest_path, PosixPath):
            dest_path = dest_path

        for src_sub_path in src_path.iterdir():
            if src_sub_path.name == ".DS_Store":
                continue

            dest_sub_path = Path(dest_path, src_sub_path.name)
            dest_sub_path.mkdir(exist_ok=True, parents=True)
            print("src_sub_path:", src_sub_path.absolute())
            num = 0
            for src_file in src_sub_path.iterdir():
                if src_sub_path.name == ".DS_Store":
                    continue

                if num >= count:
                    break
                shutil.copy2(src_file, Path(dest_sub_path, src_file.name))
                num += 1


if __name__ == '__main__':
    home_path = os.environ.get('HOME')

    src = Path(home_path, "workspace", "dataset", "dog_cat")
    out = Path(home_path, "workspace", "dataset", "dc1000")

    DataSetUtils.test(src, out, count=1000)
